/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.phonegroup;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.phonegroup.Phonegroup;

/**
 * @author Administrator (email:xxh@163.com)
 * @since 2013-01-28
 */
@Service("phonegroupService")
public class PhonegroupServiceImpl implements PhonegroupService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of Phonegroup
     ****************************************/
    public void insert(Phonegroup phonegroup) throws Exception {
        phonegroup.setGroupid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(phonegroup);
    }

    /****************************************
     * Update a instace of Phonegroup
     ****************************************/
    public void update(Phonegroup phonegroup) throws Exception {
        iDataSet4iBatis.update(phonegroup);
    }

    /****************************************
     * Delete a instace of Phonegroup
     ****************************************/
    public void delete(Phonegroup phonegroup) throws Exception {
        iDataSet4iBatis.delete(phonegroup);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(Phonegroup phonegroup) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(Phonegroup phonegroup) throws Exception {
        String statementId = phonegroup.getStatmentId();
        String mainId = phonegroup.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> phonegroupList = new ArrayList<BaseModel>();
        for (String id : ids) {
            Phonegroup model = new Phonegroup();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            phonegroupList.add(model);
        }
        iDataSet4iBatis.batchDelete(phonegroupList);
    }

    /****************************************
     * Query instaces of Phonegroup
     ****************************************/
    public List<BaseModel> queryAsList(Phonegroup phonegroup) throws Exception {
        String queryListStatement = "";
        if (phonegroup.isPaging()) {
            queryListStatement = phonegroup.getStatmentId();
            phonegroup.setStatmentId("Phonegroup.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(phonegroup);
            phonegroup.setTotalCount(baseModel.getTotalCount());
            phonegroup.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(phonegroup);
    }

    /****************************************
     * Query a instaces of Phonegroup
     ****************************************/
    public BaseModel queryAsObject(Phonegroup phonegroup) throws Exception {
        return iDataSet4iBatis.queryAsObject(phonegroup);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
